﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Admin.Common
{
    public class StringHelper
    {
        /// <summary>
        /// 驼峰字段改为mysql规范(xx_xx)
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ToDbField(string str)
        {
            string res = "";
            char[] cr = str.ToCharArray();
            foreach (char c in cr)
            {
                if (c > 'A' && c < 'Z')
                {

                    res = res == "" ? c.ToString().ToLower() : $"{res}_{c.ToString().ToLower()}";
                }
                else
                {
                    res = $"{res}{c.ToString()}";
                }
            }
            return res;
        }


    }
}
